/**
 * browserType	    浏览器类型
 * createBy	        用户id
 * createDate(int)	创建时间
 * deptId	        主部门id
 * deptName	        主部门名称
 * equipment	    设备
 * event(int)	    事件类型
 * eventName	    触发组件名称
 * eventObject
 * ip	            访问ip
 * operatingSystem	操作系统
 * resolvingPower	分辨率
 * resourceCode	    资源标识
 * resourceName	    资源名称
 * route	        页面路由地址
 * titleName	    标题
 * userName	        用户姓名
 * version	        版本号
 * uId              唯一标识（本地使用）
 * mode             访问方式
 * UA
 * photoLarge       头像
 * osVersion
 * is_upload(int)   是否上传
 *   0：未上传
 *   1：已上传
 * */

export const INIT_LOG_TABLE_WEBSQL = (DB): Promise<any> => {
    return new Promise((resolve, reject) => {
        if (!DB) {
            reject(' DB null');
        } else {
            DB.transaction(tx => {
                tx.executeSql("create table if not exists LOG_COLLECT(createBy varchar(256), deptId varchar(256), deptName, userName, event int, eventName, resourceCode, resourceName, equipment, browserType, createDate int, ip, operatingSystem, resolvingPower, route, titleName, UA, uId, version, is_upload, mode, osVersion, eventObject, photoLarge)", [], (_ctx, result) => {
                    resolve(result);
                }, (err) => {
                    console.log('INIT_LOG_TABLE 失败');
                    reject(err);
                });
            });
        }
    });
}

export const crudFromTable = (DB, sqlstr: string): Promise<any> => {
    return new Promise((resolve, reject) => {
        if (!DB) {
            reject(' DB null');
        }
        DB.transaction(tx => {
            tx.executeSql(`${sqlstr}`, [], (_ctx, result) => {
                resolve(result);
            }, (_ctx, error) => {
                console.log(`select table  error`);
                console.dir(error);
                reject(error)
            });
        });
    })
}
